package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(value = "品牌")
@RequestMapping("/admin/product")
@RestController
public class BaseTradenmarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;

    /**
     * 获取品牌分页列表
     * @param page 第几页
     * @param limit 每页数量
     * @return
     */
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result getbaseTrademark(@PathVariable("page")Long page,
                                    @PathVariable("limit")Long limit){
        Page<BaseTrademark> page1 = baseTrademarkService.page(new Page<BaseTrademark>(page, limit));
        return Result.ok(page1);
    }

    /**
     * 添加品牌
     * @return
     */
    @PostMapping("/baseTrademark/save")
    public Result addbaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }


    /**
     * 修改品牌
     * @return
     */
    @PutMapping("/baseTrademark/update")
    public Result putBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }


    /**
     * 删除品牌
     * @param id
     * @return
     */
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result delectDaseTrademark(@PathVariable("id")Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }


    /**
     * 根据id获取品牌
     * @return
     */
    @GetMapping("/baseTrademark/get/{id}")
    public Result getBaseTrademark(@PathVariable("id")Long id){
        BaseTrademark byId = baseTrademarkService.getById(id);
        return Result.ok(byId);
    }


}
